import request from '@/utils/request'
// data{
//   type:"",
//   energy:"delete",
//   data:{}
// }
const typeObj = {
  'groupManage': '/enterpriseGroup/',
  'siteFile': '/station/'
}

export function commonApi(data) {
  return request({
    url: '/enterprise' + typeObj[data.type] + data.energy,
    method: 'post',
    data: data.data
  })
}
export function stationCate(data) {
  return request({
    url: '/common/stationCate/cateList',
    method: 'post',
    data: data
  })
}

export function getDictionaries(id) {
  return request({
    url: 'admin/dictionary/allList',
    method: 'post',
    data: { pid: id }
  })
}

const listObj = {
  'site_id': '/enterprise/station/allList', // 全部站点
  'group_mater': '/admin/dictionary/allList', // 字典 管他呢 材质传12就对了
  'cate_id': '/common/stationCate/cateList', // 站点分类
  'property_id': '/common/electricPropety/allList', // 用电性质
  'scheme_id': '/enterprise/electricScheme/allList' // 电价方案

}
export function getSelectList(data) {
  if (!listObj[data.type]) {
    return null
  }
  return request({
    url: listObj[data.type],
    method: 'post',
    data: data.data || {}
  })
}
export function setSelectItem(data) {
  var arr = []
  for (var j = 0; j < data.length; j++) {
    arr.push({
      label: data[j].cate_name || data[j].name,
      value: data[j].id
    })
  }
  return arr
}
